use axum::{
    http::StatusCode, 
    serve, 
    Json, 
    Router, 
    routing,
    extract::Form
};


#[derive(serde::Deserialize)]
pub struct FormData {
    pub email: String,
    pub name: String,
}


async fn healthcheck() -> (StatusCode, Json<String>) {
    (StatusCode::OK, Json("OK".to_string()))
}

async fn subscribe(_form: Form<FormData>) -> (StatusCode, Json<String>) {
    // TODO: implement subscriber
    (StatusCode::OK, Json("OK".to_string()))
}

#[tokio::main]
async fn main(){
    let app = Router::new()
        .route("/healthcheck", routing::get(healthcheck))
        .route("/subscribe", routing::post(subscribe));

    let lisenter = tokio::net::TcpListener::bind("0.0.0.0:3001").await.unwrap();

    serve(lisenter, app).await.unwrap();

}
